Stone castles were built at Dinefwr (OS SN 611217) and Dryslwyn (OS SN 554204) near the end of the twelfth century and early in the thirteenth century. They were built by local Welsh rulers partly with the intention of repelling attacks by the English. Small settlements grew up close to each castle. In the event both castles were captured by the English in the late thirteenth century. The English maintained and strengthened the castles, and the associated townships also developed. Indeed an additional small town, Newton, was created on the Dinefwr estate.
Apart from brief intermissions the castles remained in English hands, but by the late fifteenth century their military significance had declined. The castles fell into ruin, and the inhabitants of the townships gradually departed.
In order to understand the context in which the castles at Dinefwr and Dryslwyn came into existence we need to go back to 1066. Having occupied most of England the Norman invaders made rapid progress in taking control of areas along the Welsh borders and Gwent and Glamorgan in the south. The rest of Wales fell roughly into three main territories, Gwynedd in the north, Powys in the centre, and Deheubarth in the south west. These regions continued to offer resistance to Norman and then English aggression for the next three and a half centuries.
Gwynedd, Powys, and Deheubarth did not have clear borders, the area under their authority often changed, and internal rivalry sometimes led to divisions within them. Their rulers were repeatedly called upon to revise their relationship with the king of England, generally being obliged to accept some kind of subordination though usually with a considerable degree of autonomy. In addition relationships between the regions varied from co-operation to outright conflict, and disputes between younger members of a ruling family often caused temporary or more lasting difficulties within a region. Traditional Welsh laws that included the right of every son to an equal share of their father's estate tended to exacerbate struggles within ruling families.
For more detailed information on the medieval history of Wales read A History of Wales by John Davies, available in Welsh and in English. It is the finest history book I know.
At the start of the twelfth century much of Deheubarth had come under Norman control. However, Rhys ap Gruffudd, often known as the Lord Rhys, succeeded in reuniting most of Deheubarth and he achieved a couple of decades of relative peace. He was obliged to do homage to Henry II in 1162, but Henry's position became weaker after the assassination of Thomas à Becket and as a result of the first English incursions into Ireland. Rhys ap Gruffudd took advantage of the situation to regain and extend his territory. In 1172 Henry appointed Rhys as Justiciar of south Wales, a position that meant that Welsh rulers in neighbouring areas were accountable to the king through Rhys.
Rhys ap Gruffudd lived to 1197, selecting Dinefwr as his main place of residence. There may have been a castle at Dinefwr before his reign, but it seems that the first stone structure was built then. It stood at the end of a steep sided ridge overlooking the River Tywi.
The reign of Rhys ap Gruffudd was marked by major cultural and religious achievements. He sponsored court poets, and in 1176 a festival of music and poetry was held at Cardigan castle, an event that has come to be regarded as the first national eisteddfod. Rhys provided support to the monasteries at Strata Florida and Whitland, and established an abbey at Talley, some eight miles north of Dinefwr. Talley abbey was of the Premonstratensian order, an indication of the high regard for Rhys ap Gruffudd in northern France.
Before the death of Rhys ap Gruffudd several of his sons began to argue about their share of his legacy. His oldest son, Gruffudd, died in 1201, and then two of Gruffudd's sons also became involved in the struggle. During the first decade after the death of Rhys Dinefwr castle was occupied by several members of the family in succession, but by 1208 it was held by Rhys Gryg, the second son of Rhys ap Gruffudd. Then in 1213 it was captured by his nephew Rhys Ieuanc after a short assault that included the use of firing engines, undermining of the walls, and scaling of the walls by ladder.
As a result of the power struggle in Deheubarth Llewelyn ap Iorwerth of Gwynedd, often known as Llewelyn the Great, gained a dominant position among the rulers of unoccupied Wales. In 1216 he called an assembly at Aberdyfi at which agreement was reached about the division of Deheubarth among the descendants of Rhys ap Gruffudd. It was decided that Dinefwr and most of Ystrad Tywi, the land that surrounded Dinefwr, would go to Rhys Gryg. A period of relative stability followed that lasted until the death of Rhys Gryg in 1233.
The earliest surviving parts of Dinefwr castle were probably constructed during the reign of Rhys Gryg. They include the large circular keep and sections of the wall surrounding the inner ward. One of the non-military achievements for which Rhys Gryg is remembered was his patronage of local medical services. He gave support to his physician Rhiwallon in establishing a hereditary line of physicians at the village of Myddfai, a service that continued until the middle of the eighteenth century.
More information on the history of Dinefwr can be found in R A Griffiths, A Tale of Two Towns, Studies in Carmarthenshire History, 1991, 4, 205-226.